package com.ellecity06.androidaddflutter

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.MethodChannel

import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel.MethodCallHandler


class MainActivity : AppCompatActivity() {
    private val textView: TextView by lazy { findViewById(R.id.tv_text) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        textView.setOnClickListener {
            startActivity(
                FlutterActivity
                    .withCachedEngine(AppApplication.ENGINE_ID)
                    .build(this)
            )
            val appApplication = application as AppApplication
            appApplication.channel.invokeMethod("setTitle", "我是安卓传递过来的标题")
        }
    }

    override fun onResume() {
        super.onResume()
        val app = application as AppApplication
        textView.text = "flutter页面点击次数: ${app.count}"
    }
}